#include <arch.h>
#include <config.h>
#include <i2c.h>
#include <util.h>
#include <time.h>

int MODEM_Init()
{
    // GPIO
    rGPACON |= 1 << 7; // RST_BB, OUT
    rGPGCON = (rGPGCON & ~(0x3 << 22)) | (0x1 << 22); // ONOFF_BB, OUT

    // Reset modem
    rGPADAT &= ~(1 << 7);
    msleep(20);
    rGPADAT |= (1 << 7);
    msleep(20);

    // Enable modem
    printf("Modem is initializing. It will take several seconds. Please wait...\n");
    rGPGDAT |= (1 << 11);
//    msleep(8000);
    ostdelay(8000000);
    rGPGDAT &= ~(1 << 11);

    printk("Modem has been initialized\n");

    return 0;
}

void MODEM_Close()
{
    // Disable modem
    printf("Modem is closing. It will take several seconds. Please wait...\n");
    rGPGDAT |= (1 << 11);
    ostdelay(5000 * 20);
    rGPGDAT &= ~(1 << 11);

    printk("Modem has been closed.\n");
}
